import api from './index'
import { axios, request } from '@/utils/request'
import Qs from 'qs'

// 获取-公司-权限 
export function getPermissionByCom() {
  return axios({
    url: '/api/user/permisson/manage/listByCompany',
    method: 'post',
  })
}

// 获取-员工-权限
export function getPermissionByUser() {
  return axios({
    url: '/api/user/permisson/manage/listByUser',
    method: 'post'
  })
}

// 获取-me 菜单权限 getInfo-permisson
export function getInfo() {
  return axios({
    url: '/api/oa/permisson/manage/me',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

// 获取当前账号信息 getUserInfo
export function getUserInfo() {
  return axios({
    url: '/api/oa/staff/manage/me',
    method: 'post'
  })
}


// 企业注册    (userName 昵称，注册时暂无)
export function register(code, companyName, password, phone) {
  let params =
  {
    "code": code,
    "companyName": companyName,
    "password": password,
    "username": phone,
    "staffName": phone
  }
  return axios({
    url: '/api/oa/company/open/register',
    method: 'post',
    data: params,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }

  })
}

// 刷新token
export function RefreshToken(refreshToken) {
  return axios({
    url: '/api/user/user/open/refreshToken',
    method: 'post',
    data: Qs.stringify({
      refreshToken
    }),
  })
}

// 登入 （获取token）
export function login(parameter) {
  return axios({
    url: '/api/login',
    method: 'post',
    data:{
      "account": parameter.username,
      "password": parameter.password
    }
    
  })
}

// 获取验证码   (旧getCode)
export function getSmsCaptcha(phone) {
  return axios({
    url: '/api/user/user/open/code',
    method: 'post',
    data: Qs.stringify({
      phone
    }),
  })
}

// //退出登入
// export function logout() {
//   return axios({
//     url: '/auth/logout',
//     method: 'post',
//     headers: {
//       'Content-Type': 'application/json;charset=UTF-8'
//     }
//   })
// }

export function getCurrentUserNav(token) {
  return axios({
    url: '/user/nav',
    method: 'get'
  })
}


/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step(parameter) {
  return axios({
    url: api.twoStepCode,
    method: 'post',
    data: parameter
  })
}